<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<pre>
 openssl asn1parse -out temp.ans -i -inform PEM < test.pem
    0:d=0  hl=4 l= 604 cons: SEQUENCE
    4:d=1  hl=2 l=   1 prim:  INTEGER           :00
    7:d=1  hl=3 l= 129 prim:  INTEGER           :CF6E92C03CFF469E6B74B32FE1A9D89FF60BD71B9F80E7021C1EDFC66BDCC559A1FB46B90B9B96DCB35B6ECE4564A3AC277F8E5018D96EC7BD3600C4ACA9520BA7E40D38F1EDD170D8E2FA2C3E1B8AD98DC27016D3075A303C7485D06EBA1ABC5238B39000F60709A6CFE24D1E965ADB12C1278537C093F99C455394D7689747
  139:d=1  hl=2 l=   3 prim:  INTEGER           :010001
  144:d=1  hl=3 l= 128 prim:  INTEGER           :6BA94953AB9517331C34AAD81C390A6D23C84B7253DC148A3CCC2D7B0FFABB17658244D7C05595FCA0BEC109206D36A220B20CCC37C98ABCF2D0B79F5CBA591132707066492B0760C2B94C1DD8D19B7AAA1A3D558E9511C73AA5A60DADB5D1836FBDA4AA2300DC9EAFB844C26548BB13485643D55E6D5575BD7370D22A419AB1
  275:d=1  hl=2 l=  65 prim:  INTEGER           :E81A6E34DC8CC87CD1591B8E6107A72CB6063C0541C1E49943CF2E43FA49EF9CFB07739CFAE5F30AECAB32EB6BB9CBC79DA5976E8C67E918FB8CA7986B80A41F
  342:d=1  hl=2 l=  65 prim:  INTEGER           :E4C9E0D56CCCBC9C32FE67A0C8C0FACD013E06726DCBCFF9D0D57188A5FE65143524CC70C5A97C3A2E4194E84995EC7F4DA1130D85EDCA5226ECDEE9180B67D9
  409:d=1  hl=2 l=  64 prim:  INTEGER           :74EAE37B03627397D48913857C4133A825252CD4E513FBC86CCD0F9C34974BF982C67529AD856A11A5B87394FD96011DD3BED7725B8DF8709A3E772A237510B7
  475:d=1  hl=2 l=  65 prim:  INTEGER           :A86A5F625C63DE1791862ADC75CB7113C5ED55AB985D66EC7BA9139946B01CD22248C361E46F5DEE2A2CC6A3B3BF744745EAE36E99FF306707166904E7594609
  542:d=1  hl=2 l=  64 prim:  INTEGER           :73B0D7A056071FD028E6D7B27ECF2EAD8B52661F290F76C659B74F285073B18D78BC6073BD8FEE43D308CC2670F2477BDCC3B15E87FDA17C00E7AB18DCF384FA
</pre>
</body>
</html>
<script src="base64.js"></script>
<script src="BigInt.js"></script>
<script src="Barrett.js"></script>x
<script src="RSA_Stripped.js"></script>
<script>

// openssl rsa -pubin -inform PEM -modulus -noout < public_key.pem
// openssl asn1parse -out temp.ans -i -inform PEM < private_key.pem

// var private_key = '6BA94953AB9517331C34AAD81C390A6D23C84B7253DC148A3CCC2D7B0FFABB17658244D7C05595FCA0BEC109206D36A220B20CCC37C98ABCF2D0B79F5CBA591132707066492B0760C2B94C1DD8D19B7AAA1A3D558E9511C73AA5A60DADB5D1836FBDA4AA2300DC9EAFB844C26548BB13485643D55E6D5575BD7370D22A419AB1'
// var public_key = 'CF6E92C03CFF469E6B74B32FE1A9D89FF60BD71B9F80E7021C1EDFC66BDCC559A1FB46B90B9B96DCB35B6ECE4564A3AC277F8E5018D96EC7BD3600C4ACA9520BA7E40D38F1EDD170D8E2FA2C3E1B8AD98DC27016D3075A303C7485D06EBA1ABC5238B39000F60709A6CFE24D1E965ADB12C1278537C093F99C455394D7689747'

var private_key = '8E40F8BA3F3D695A8742E7847475FB710EBBA9111E68C87A74929D2D11F02143E6198C55C380F73BFF3627BF499695C83C899AE553CC451EF27B6A49C7353466A2DAAC4DEBCE743B84291FA4BB5EDA216E27F20CD6B157393FE93BB074A38648B2482BB260877BB417CFBB6333C47548A377265CDDFEE11853D0CE93EAAA1C01'
var public_key = 'D548E149FCA2E37BCEAC06AC3E72373EFA4242CE35A5761E48F7E9164184FE75BA0581FEFAE13446B73E658112202639AD9B941D408E346F941C65C5AA31B27FD2CE065BD2524149BD445393F23AC0418EF6461A425635BBF5716B796AFD69D2FB218F6B92A6BF5B27A5F54013AF96EDD47D8C5C5F3AC39940AA0F531BDA5789'

var s = "fasdfas你好dfasdf"
// var s = "fasdfadddddddfasdf"

console.log("明文：", s)

// setMaxDigits(260);
// setMaxDigits(131); //131 => n的十六进制位数/2+3
setMaxDigits(130);
key = new RSAKeyPair(
 "10001",
 private_key,
 public_key
);

// var pad =  RSAAPP.PKCS1Padding
// var pad = RSAAPP.NoPadding
var pad = ''

var b64_s = Base64.encode(s)
console.log('b64_s: ', b64_s)

var encrypted = encryptedString(key, b64_s, pad)
console.log("encrypted: ", encrypted)
console.log("encrypted b64: ", Base64.encode(encrypted))

var decrypted = decryptedString(key, encrypted, pad)
console.log("decrypted : ", decrypted)
console.log("decrypted: ", Base64.decode(decrypted, utf8decode = false))


// 下面的代码js 自己加密、自己解密OK

// setMaxDigits(130);
// var key = new RSAKeyPair(
//  "10001",
//  "12e8da920d4599458e84ec5ef1656161807f427d05eb79182b7418259d6f6c14364d1f5caf9130c8d9d9d6ea71d1bdbc87781a46a16bcb9e672814fed3b9c96ddffe0a1b0955ae68055c8f92fef518a04fc32a2ea8390e617cc5556a251f9ae9eee70a32e579cb3e9f298848a9b3aaf634f5930ffbf74473f7cb6c0cefee1751",
//  "130ebebd67b16a9ab2c53a437badbf8f01a80c750095a7fcfe95742c3d5ed1abb318babc5cb5d9350fee4da65ee074f65e1758117e6945f0fcfc8137528053ce9d1da8618890dee24e5e0bf8c87795bb1d09eddd544640824ee0dd0ea9fd908d27b0f8a1ae5c37f3647fbf2f5795500ad76c195b3387d0458a8f51b701472301"
// );
// var b64_s = Base64.encode(s)
// console.log('base64: ', b64_s)
// var encrypted = encryptedString(key, b64_s);
// console.log("encrypted: ", encrypted)


// var decrypted = decryptedString(key, encrypted);
// console.log("decrypted: ", Base64.decode(decrypted, utf8decode = false))
</script>
